package com.yst.sqlbuilder;

import com.yst.lambda.LambdaFuncUtils;
import com.yst.lambda.TableFieldFunc;
import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;

@Data
@Accessors(chain = true)
public class OrderBy<T> implements Serializable {

    public enum OrderByMode{
        ASC("asc"),
        DESC("desc");
        public final String sql;
        OrderByMode(String sql){
            this.sql=sql;
        }
    }

    private String field;

    private String mode;

    public OrderBy(String field,OrderByMode mode){
        this.field=field;
        this.mode=mode.sql;
    }

    public OrderBy(TableFieldFunc<T,?> field,OrderByMode mode){
        this.field= LambdaFuncUtils.getFieldName(field);
        this.mode=mode.sql;
    }

    public OrderBy(String field){
        this(field,OrderByMode.ASC);
    }

    public OrderBy(TableFieldFunc<T,?> field){
        this(field,OrderByMode.ASC);
    }


}
